namespace HelpInfo.GetMsWeb.Migrations
{
    using HelpInfo.GetMsWeb.Models;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<HelpInfo.GetMsWeb.Models.ApplicationDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(HelpInfo.GetMsWeb.Models.ApplicationDbContext context)
        {
            this.AddUserAndRoles();
        }
        bool AddUserAndRoles()
        {
            bool success = false;
            var idManager = new IdentityManager();
            success = idManager.CreateRole("Agent");
            if (!success == true) return success;
            success = idManager.CreateRole("Admin");
            if (!success == true) return success;
            success = idManager.CreateRole("Dev");
            if (!success) return success;
            var newAgent = new ApplicationUser()
            {
                UserName = "agent",
            };
            var newAdmin = new ApplicationUser()
            {
                UserName = "admin",
            };
            var newDev = new ApplicationUser()
            {
                UserName = "dev",
            };
            // Be careful here - you  will need to use a password which will 
            // be valid under the password rules for the application, 
            // or the process will abort:
            success = idManager.CreateUser(newAgent, "p@ssword");
            if (!success) return success;
            success = idManager.CreateUser(newAdmin, "p@ssword");
            if (!success) return success;
            success = idManager.CreateUser(newDev, "p@ssword");
            if (!success) return success;
            success = idManager.AddUserToRole(newAgent.Id, "Agent");
            if (!success) return success;
            success = idManager.AddUserToRole(newAdmin.Id, "Admin");
            if (!success) return success;
            success = idManager.AddUserToRole(newDev.Id, "Dev");
            if (!success) return success;
            return success;
        }
    }
}

